<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        let arr=[1,2,3]
        for(let i = 0; i < arr.length; i++){
        console.log(arr[i]);
        }
        let a=0
        while(a<arr.length){
            console.log(arr[a])
            a++
        }
        function add(x,y){
        return x + y
       }

       function mul(x,y){
        return x * y
       }

        function number(x,y,fun){
        return fun(x,y)
       }

       let number1 = mul(5,6)
       console.log(number1)

       let b = number(2,3,mul)
       console.log(b)
       let c = number(3,6,(x,y)=>{return x+y})
       console.log(c)
       let arr1=["c++","python","java"]
       let arr2 = [4,5,6,7]
       console.log("这是第二个数组aar1:" + arr1)
       console.log("这是第三个数组aar2:" + arr2)
       arr2.sort((x,y)=>{       
            return x-y
       })
       console.log("从小到大:" + arr2)
        arr2.sort((x,y)=>{
            return y-x
       })
       console.log("从大到小:" + arr2)
       arr1.sort((x,y)=>{
            return x.length - y.length
       })
       console.log("从短到长:" + arr1)

        arr1.sort((x,y)=>{
            return y.length - x.length
       })
       console.log("从长到短:" + arr1)
       //forEach 遍历
        const numbers1 = [1, 2, 3, 4, 5];
        const forEachResult = [];
        numbers1.forEach(num => forEachResult.push(num * 2));
        console.log("forEach结果:" + forEachResult.join(', '))
        //map 替换成新数组
        const numbers2 = [1, 2, 3, 4, 5];
        const mapResult = numbers2.map(num => num * 2);
        console.log("map结果:" + mapResult)  
    
        //find 查找满足条件的第一个元素
        const numbers3 = [5, 12, 8, 130, 44];
        const findResult = numbers3.find(num => num > 10);
        console.log("find结果:" + findResult) 
    </script>
</body>
</html>